<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
</head>

<body>
    <header class="aui-bar aui-bar-nav" style="background-color: #03a9f4;position:fixed;" id="header">
        <a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="title">
            检测单列表
        </div>
    </header>
    <script id="chkBillTemp" type="text/x-dot-template">

        {{~ it:value:index}}
        <li class="aui-list-item" onclick="setChkBill('{{= it[index].sysid }}','{{= it[index].code }}','{{= it[index].mrlCode }}','{{= it[index].mrlName }}',
            '{{= it[index].opCode }}','{{= it[index].opName }}','{{= it[index].chkTypeName }}','{{= it[index].supplierName }}','{{= it[index].ext06 }}',
            '{{= it[index].actualQty }}','{{= it[index].cjqty }}','{{= it[index].isTightened }}','{{= it[index].tightenedEndDate }}','{{= it[index].ext07_k }}',
            '{{= it[index].processStateName }}','{{= it[index].nactualQty }}');">
            <div class="aui-media-list-item-inner">
                <div class="aui-list-item-inner ">
                    <div class="aui-list-item-text">
                        <div class="aui-list-item-title aui-font-size-14">
                            检测单号:{{= it[index].code }}
                        </div>
                    </div>
                    <div class="aui-list-item-text aui-font-size-12">
                        检测类型:{{= it[index].chkTypeName == null ? '' :  it[index].chkTypeName}}
                    </div>
                    <div class="aui-list-item-text aui-font-size-12">
                        供应商名称:{{= it[index].supplierName == null ? '' :  it[index].supplierName}}
                    </div>
                    <div class="aui-list-item-text aui-font-size-12">
                        物料编码:{{= it[index].mrlCode == null ? '' :  it[index].mrlCode}}
                    </div>
                    <div class="aui-list-item-text aui-font-size-12">
                        物料名称:{{= it[index].mrlName == null ? '' :  it[index].mrlName}}
                    </div>
                    <div class="aui-list-item-text aui-font-size-12">
                        批次号:{{= it[index].ext06 == null ? '' :  it[index].ext06}}
                    </div>
                    <div class="aui-list-item-text aui-font-size-12">
                        审核状态:{{= it[index].processStateName }}
                    </div>
                    <div class="aui-list-item-text aui-font-size-12">
                        处理结果:{{= it[index].chkResultName }}
                    </div>
                    <div class="aui-list-item-text aui-font-size-12">
                        生产数量:{{= it[index].nactualQty }}
                    </div>
                    <div class="aui-list-item-text aui-font-size-12">
                        检测等级:{{= it[index].ext07_k }}
                    </div>
                </div>
            </div>
        </li>
        {{~}}

    </script>
    <div class="aui-content aui-margin-b-15" style="margin-top:50px;">
        <div class="aui-searchbar" id="search" style="position: relative;">
            <div class="aui-searchbar-input aui-border-radius">
                <i class="aui-iconfont aui-icon-search"></i>
                <div class="aui-searchbar-input">
                    <form action="javascript:doSearch();">
                        <input type="search" placeholder="检测单号" id="chkBillCodeS">
                    </form>
                </div>
            </div>
            <div class="aui-searchbar-input aui-border-radius">
                <i class="aui-iconfont aui-icon-search"></i>
                <div class="aui-searchbar-input">
                    <form action="javascript:doSearch();">
                        <input type="search" placeholder="供应商名称" id="supplierName">
                    </form>
                </div>
            </div>
        </div>
        <div class="aui-searchbar" id="search" style="position: relative;">
            <div class="aui-searchbar-input aui-border-radius">
                <i class="aui-iconfont aui-icon-search"></i>
                <div class="aui-searchbar-input">
                    <input type="boxnum" placeholder="箱码" id="boxnum">
                </div>
            </div>
        </div>
        <div class="aui-searchbar" id="search" style="position: relative;">
            <div class="aui-searchbar-input aui-border-radius">
                <i class="aui-iconfont aui-icon-search"></i>
                <div class="aui-list-item-label">检测等级</div>
                <div class="aui-searchbar-input">
                        <select id="level" multiple="multiple"></select>
                </div>
            </div>
        </div>
        <div class="aui-searchbar" id="search" style="position: relative;">
            <div class="aui-searchbar-input aui-border-radius">
                <i class="aui-iconfont aui-icon-search"></i>
                <div class="aui-list-item-label">审核状态</div>
                <div class="aui-searchbar-input">
                        <select id="shstate" multiple="multiple"></select>
                </div>
            </div>
        </div>
        <div class="aui-searchbar" id="search" style="position: relative;">
            <div class="aui-searchbar-input aui-border-radius">
                <i class="aui-iconfont aui-icon-search"></i>
                <div class="aui-searchbar-input">
                    <form action="javascript:doSearch();">
                        <input type="search" placeholder="物料编码" id="mrlCode">
                    </form>
                </div>
            </div>
            <div class="aui-searchbar-input aui-border-radius">
                <i class="aui-iconfont aui-icon-search"></i>
                <div class="aui-searchbar-input">
                    <form action="javascript:doSearch();">
                        <input type="search" placeholder="批次号" id="lotCode">
                    </form>
                </div>
            </div>
            <div class="aui-btn aui-btn-primary" style="margin-right: 0.5rem;background-color: #03a9f4"
                onclick="doSearch()">搜索</div>
        </div>
    </div>

    <div class="aui-content aui-margin-b-15">
        <ul class="aui-list aui-media-list" id="chkBillList">

        </ul>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/doT.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript">
    apiready = function () {
        $("#boxnum").focus();
        doSearch();
        getLevelCombox();
        getStateCombox();
    };

    //查询服务器ip
    function getLevelCombox() {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getUdiList";
        var data = {
            values: {
                code: "MRL_CHECK_LEVEL",
                appVersion: api.appVersion,
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 30,
            returnAll: false,
            data: data
        }, function(ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");

                //返回成功
                if (myobj.code == "0") {
                    var list = eval(myobj.list);
                    var html = "";
                    for (var i = 0; i < list.length; i++) {
                        html += "<option value='" + list[i].value + "'>" + list[i].label + "</option>";
                    }
                    $api.html($api.byId("level"), html);

                    //失败
                } else if (myobj.code == "1") {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            } else {
                api.toast({
                    msg: JSON.stringify(err),
                    duration: 3000
                });
            }
        });
    }

    //查询服务器ip
    function getStateCombox() {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getUdiList";
        var data = {
            values: {
                code: "MRL_CHECK_STATE",
                appVersion: api.appVersion,
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 30,
            returnAll: false,
            data: data
        }, function(ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");

                //返回成功
                if (myobj.code == "0") {
                    var list = eval(myobj.list);
                    var html = "";
                    for (var i = 0; i < list.length; i++) {
                        html += "<option value='" + list[i].value + "'>" + list[i].label + "</option>";
                    }
                    $api.html($api.byId("shstate"), html);

                    //失败
                } else if (myobj.code == "1") {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            } else {
                api.toast({
                    msg: JSON.stringify(err),
                    duration: 3000
                });
            }
        });
    }
    //查询检测单
    function doSearch() {

        //审核状态：0未处理，3处理中，7已处理，8已确认，9已取消
        var processState = '0';
        //检测单类型（1-材料检测单，2-在制品检测单，3-5S检测单，4-4W检测单，5-设备检测单）
        var chkBillType = '1';
        //检测单号
        var chkBillCodeS = $("#chkBillCodeS").val();
        var supplierName = $("#supplierName").val();
        var mrlCode = $("#mrlCode").val();
        var level = $("#level").val();
        var shstate = $("#shstate").val();
        var boxnum = $("#boxnum").val();
        var lotCode = $("#lotCode").val();
        var un = localStorage.getItem('un');
        if(level == null || level == 'null' || level == undefined){
            level = '';
        }
        if(shstate == null || shstate == 'null' || shstate == undefined){
            shstate = '';
        }
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getChkBill_ll";
        var data = {
            values: {
                processState: processState,
                appVersion: api.appVersion,
                chkBillType: chkBillType,
                code: chkBillCodeS,
                supplierName: supplierName,
                mrlCode: mrlCode,
                level: level,
                state: shstate,
                lotCode: lotCode,
                boxnum: boxnum,
                un: un,
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 30,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                if (myobj.code == '0') {
                    var list = eval(myobj.list);

                    var evaluation = doT.template($api.dom('#chkBillTemp').innerHTML);
                    $api.dom('#chkBillList').innerHTML = evaluation(list);
                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }

    //选则返回函数
    function setChkBill(id, code, mrlCode, mrlName, opCode, opName, chkTypeName,supplierName ,lotCode,actualQty,cjqty,isTightened,tightenedEndDate ,ext07_k,state,nactualQty) {
        // //api.closeWin();
        // var name = api.pageParam.name;

        // if(isTightened == 'Y'){
        //     isTightened = '是';
        // }else{
        //     isTightened = '否';
        // }
        // api.execScript({
        //     name: name,
        //     script: 'setChkBill("' + id + '","' + code + '","' + mrlCode + '","' + mrlName + '","' + opCode + '","' + opName + '","' + chkTypeName + '","' + supplierName + '","' + lotCode 
        //         + '","' + actualQty + '","' + cjqty + '","' + isTightened + '","' + tightenedEndDate + '","' + ext07_k + '","' + state + '","' + nactualQty + '")'
        // });

        api.openWin({
            name: 'qcmChkBillCl_ll',
            url: 'qcmChkBillCl_ll.html',
            pageParam: {
                id: id,
                code: code,
                mrlCode: mrlCode,
                mrlName: mrlName,
                opCode: opCode,
                opName: opName,
                chkTypeName: chkTypeName,
                supplierName: supplierName,
                lotCode: lotCode,
                actualQty: actualQty,
                cjqty: cjqty,
                isTightened: isTightened,
                tightenedEndDate: tightenedEndDate,
                ext07_k: ext07_k,
                state: state,
                nactualQty: nactualQty,
                name: "qcmSelectChkBill_ll",
            }
        });
    }

    //条码监听回车事件
    $("#boxnum").on('keypress', function(e) {
        var keycode = e.keyCode;
        var tm = $(this).val();
        if (keycode == '13') {
            $("#boxnum").blur();

            //条码校验
            tmCheck(tm);
        }
    });

    function tmCheck(tm){

        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getTmCheck";
        var data = {
            values: {
                tm: tm, //条码
                //getMrl: 'true',
                getBox:'true',
                appVersion: api.appVersion,
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 30,
            returnAll: false,
            data: data
        }, function(ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var  myobj = eval("(" + data + ")");
                //成功
                if (myobj.code == '0') {

                    $('#boxnum').val(myobj.boxnum);

                    doSearch();
                } else if (myobj.code == '1') {

                    $("#boxnum").val("");
                    $("#boxnum").select();
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            } else {
                alert(JSON.stringify(err));
            }
        });
    }

    //返回按钮
    function closeWin() {
        api.closeWin({});
    }
</script>

</html>